#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int N = 1e6+10;
int heap[N];
int n;

// 向上调整
void up(int child){
    int parent = child / 2;
    while(parent >= 1 && heap[child] < heap[parent])
    {
        swap(heap[child],heap[parent]);
        child = parent;
        parent = child / 2;

    }
}

// 向下调整
void down(int parent){
    int child = parent * 2;
    while(child <= n){
        if(child + 1 <= n && heap[child + 1] < heap[child]) child++;
        if(heap[child] >= heap[parent]) return;
        if(heap[child] < heap[parent])
        {
            swap(heap[child],heap[parent]);
            parent = child;
            child = parent * 2;            
        }
    }
}

void push(int x){
    heap[++n] = x;
    up(n);
}

void pop(){
    heap[1] = heap[n];
    n--;
    down(1);
}

int top(){
    return heap[1];
}

int size(){
    return n;
}



int main(){
    int num;
    cin >> num;
    while(num--)
    {
        int op;
        cin >> op;
        if(op == 1)
        {
            int x; cin >> x;
            push(x);
        }
        else if(op == 2)
        {
            cout << heap[1] << endl;
        }
        else{
            pop();
        }
    }
    
    return 0;
}

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;

int n,k;
priority_queue<int> heap;


int main()
{
    cin >> n >> k;
    
    
    return 0;
}